package com.baidu.mobstat;

import android.content.Context;
import com.baidu.mobstat.a.b;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import org.json.JSONArray;
import org.json.JSONObject;

class a
  implements Thread.UncaughtExceptionHandler
{
  private static a a = new a();
  private Thread.UncaughtExceptionHandler b = null;
  private Context c = null;

  public static a a()
  {
    return a;
  }

  private void a(long paramLong, String paramString)
  {
    if ((this.c == null) || (paramString == null) || (paramString.trim().equals("")))
      return;
    try
    {
      JSONObject localJSONObject = new JSONObject();
      localJSONObject.put("t", paramLong);
      localJSONObject.put("c", paramString);
      JSONArray localJSONArray = b(this.c);
      if (localJSONArray == null)
        localJSONArray = new JSONArray();
      localJSONArray.put(localJSONObject);
      FileOutputStream localFileOutputStream = this.c.openFileOutput("__local_except_cache.json", 0);
      localFileOutputStream.write(localJSONArray.toString().getBytes());
      localFileOutputStream.flush();
      localFileOutputStream.close();
      b.a("SDKCrashHandler", "Save Exception String Successlly");
      return;
    }
    catch (Exception localException)
    {
      b.a("SDKCrashHandler", localException);
    }
  }

  public void a(Context paramContext)
  {
    if (this.b == null)
    {
      this.b = Thread.getDefaultUncaughtExceptionHandler();
      Thread.setDefaultUncaughtExceptionHandler(this);
    }
    if (this.c != null)
      return;
    this.c = paramContext.getApplicationContext();
  }

  protected JSONArray b(Context paramContext)
  {
    Object localObject = null;
    if (paramContext == null)
      return null;
    File localFile = new File(paramContext.getFilesDir(), "__local_except_cache.json");
    FileInputStream localFileInputStream;
    StringBuffer localStringBuffer;
    try
    {
      if (localFile.exists());
      localFileInputStream = paramContext.openFileInput("__local_except_cache.json");
      localStringBuffer = new StringBuffer();
      byte[] arrayOfByte = new byte[1024];
      int i = localFileInputStream.read(arrayOfByte);
      if (i == -1)
        break label118;
      label99: label118: localStringBuffer.append(new String(arrayOfByte, 0, i));
    }
    catch (Exception localException1)
    {
      b.a("SDKCrashHandler", localException1);
      try
      {
        localFile.delete();
        return localObject;
      }
      catch (Exception localException2)
      {
        b.a("SDKCrashHandler", localException2);
        return localObject;
      }
      localFileInputStream.close();
      if (localStringBuffer.length() != 0);
      for (JSONArray localJSONArray = new JSONArray(localStringBuffer.toString()); ; localJSONArray = null)
      {
        localObject = localJSONArray;
        break label99:
      }
    }
  }

  public void uncaughtException(Thread paramThread, Throwable paramThrowable)
  {
    StringWriter localStringWriter = new StringWriter();
    PrintWriter localPrintWriter = new PrintWriter(localStringWriter);
    paramThrowable.printStackTrace(localPrintWriter);
    localPrintWriter.close();
    String str = localStringWriter.toString();
    b.a("SDKCrashHandler", str);
    a(System.currentTimeMillis(), str);
    if (this.b.equals(this))
      return;
    this.b.uncaughtException(paramThread, paramThrowable);
  }
}

/* Location:           C:\Users\god\Desktop\liunianjishiben_V1.1_mumayi_3745b_dex2jar.jar
 * Qualified Name:     com.baidu.mobstat.a
 * JD-Core Version:    0.5.4
 */